package com.neusoft.question;

import java.util.Scanner;

/**
 * Java Scanner类的应用
 * @author LYW
 *
 */
public class ScannerTest {

	public static void main(String[] args)  {
		//实例化Scanner
		Scanner sc = new Scanner(System.in);
		int iInScan;
		String strInScan;
		
		//扫描输入整数，如果有，输出并退出，如果没有继续输入
		while(true) {
		System.out.println("请输入一个学号：");
		if(sc.hasNextLine()) {
			try {
				//sc.nextLine();
				iInScan = sc.nextInt();
				
				
				//sc.nextLine();
				System.out.println("你输入的学号为"+iInScan);
				break;
			} catch (Exception e) {
				// TODO: handle exception
				System.out.println("Exception thrown :" +e);
				sc.nextLine();
				
				
			}
						
		}
		}
		//扫描输入字符串
				try {
					System.out.println("请输入班级：");
					if(sc.hasNext()) {
						strInScan = sc.next();
						System.out.println("你输入的班级为"+strInScan);
												
					}
				}catch(Exception e){
					System.out.println("Exception thrown" + e);
					sc.nextLine();
					
				}
					
		
		
		//nextline 的应用
		
			System.out.println("请输入班级：");
			if(sc.hasNextLine()) {
				sc.nextLine();
				strInScan = sc.nextLine();
				System.out.println("你输入的班级为"+strInScan);
				
				
			}
			
		sc.close();
		
		int a = -5;
		System.out.println(a<<2);
		
	}

}
